package com.yanqu.road.server.manager.cricketcourt.timer;

import com.yanqu.road.logic.bussiness.DaoHelper;
import com.yanqu.road.server.manager.cricketcourt.CrossCricketCourtMgr;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.executor.GeneralTask;

public class CrossCricketCourtTask extends GeneralTask {

    // 切换轮次时间
    private long changeRoundTime;

    // 生成分组时间
    private long generateGroupTime;

    // 竞技场结算奖励时间
    private long courtSendRewardTime;


    // debug time
    private long debugTime;


    @Override
    public void doRun() {
        // 系统没开放不需处理
        if (!CrossCricketCourtMgr.channelSystemOpen()) {
            return;
        }
        if (System.currentTimeMillis() - changeRoundTime > DateHelper.SECOND_MILLIONS) {
            changeRoundTime = System.currentTimeMillis();
            try {
                // 切换轮次
                CrossCricketCourtMgr.changeRound();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        if (System.currentTimeMillis() - courtSendRewardTime > DateHelper.SECOND_MILLIONS * 10) {
            courtSendRewardTime = System.currentTimeMillis();
            try {
                // 竞技场结算奖励
                CrossCricketCourtMgr.sendRankReward();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }



        // debug定时任务，方便测试数据
        if (System.currentTimeMillis() - debugTime > DateHelper.SECOND_MILLIONS * 10) {
            debugTime = System.currentTimeMillis();
            try {
                // debug
                CrossCricketCourtMgr.debug();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }


    }
}
